﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using System.Data.SqlClient;

namespace QuanLyBanVeXe
{
    public partial class ReportTuyenDi : Form
    {
        public SqlConnection myConnection;
        public SqlCommand myCommand;
        
        public ReportTuyenDi()
        {
            InitializeComponent();
        }

        private void FormBaoCao_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dsTuyenDi.TuyenDi' table. You can move, or remove it, as needed.
            this.AcceptButton = btnOK;
            cbbLoaiXe.DataSource = LayLoaiXe();
            cbbLoaiXe.DisplayMember = "LoaiXe";
            cbbBenDi.DataSource = LayTuyenDi();
            cbbBenDi.DisplayMember = "BenDiBenDen";
            cbbBenDi.Text = null;
            cbbLoaiXe.Text = null;
            this.TuyenDiTableAdapter.Fill(this.dsTuyenDi.TuyenDi);
            this.reportViewer.RefreshReport();
            
        }
        public DataTable LayLoaiXe()
        {
            SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS; database=QuanLyBanVeXe; integrated security=true");
            DataTable dt = new DataTable();
            string sql = "select LoaiXe from LoaiXe";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.Fill(dt);
            return dt;
        }
        public DataTable LayTuyenDi()
        {
            SqlConnection con = new SqlConnection(@"server=.\SQLEXPRESS; database=QuanLyBanVeXe; integrated security=true");
            DataTable dt = new DataTable();
            string sql = "select BenDiBenDen from TuyenDi";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.Fill(dt);
            return dt;
        }
       
        private void btnOK_Click(object sender, EventArgs e)
        {
            
            if (txtGiaVe.Text.Trim().Length != 0)
                this.TuyenDiTableAdapter.FillBy(this.dsTuyenDi.TuyenDi,Convert.ToDecimal(txtGiaVe.Text), cbbBenDi.Text, cbbLoaiXe.Text);
            else
                this.TuyenDiTableAdapter.LocDuLieu(this.dsTuyenDi.TuyenDi, cbbBenDi.Text, cbbLoaiXe.Text);
            
            this.reportViewer.RefreshReport();
        }

        private void ReportTuyenDi_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            Close();
        }

        private void ReportTuyenDi_FormClosed_1(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            this.Close();
        }
        
    }
}
